/******************************************************************************
*
* Copyright (C), 2013, mophie. Co., Ltd. All Rights Reserved. 
*
* Version: v1.0.0
* $$Datae: 2013-7-5  
*
* Description:    
*   IIC Function
*
* Function List: 
* 
* History:        
*         1. $$data:  2013-7-5
*            Author:  JPM team         
*
******************************************************************************/
#ifndef __IIC_H
#define __IIC_H

/***Include file list*********************************************************/
#include "io_api.h"
#include "pio.h"
/***Macro deifne*************************************************************/
#define SDA_INPUT_MODE    0
#define SDA_OUTPUT_MODE   1
#define SCL_LOW   0
#define SCL_HIGH  1
#define SDA_LOW   2
#define SDA_HIGH  3
#define RST_LOW   4
#define RST_HIGH  5
#define IIC_ACK    1
#define IIC_NACK   0
#define IIC_READ      1
#define IIC_WRITE     0
#define IIC_FAILE_TIME  6
#define IIC_INDEX_SCL   0
#define IIC_INDEX_SDA   1
#define AUTH_CHIP_RESET 2
#define IIC_STABLE_TIME   4
#define IIC_DATA_INTREVAL 20
#define IIC_WATI_ACK_TIME 240
#define IIC_ACK_RIGHT   1
#define IIC_ACK_WRONG   0
#define IIC_SDA_PORT                        PIOB
#define IIC_SDA_PIN_NUM                     23
#define IIC_SCL_PORT                        PIOA
#define IIC_SCL_PIN_NUM                     12
#define AUTH_RST_PORT                       PIOA
#define AUTH_RST_PIN_NUM                    14

/**********user config*********************************************************/
#define IIC_AUTH_ADDR   0x22

/***************************global variables*********************************/

/*******************Function list***********************************************/
void AUTH_CHIP_Rst(void);
void IIC_SCL_Init(void);
void IIC_SDA_Set(uint8_t mode);
void IIC_IO_Set(uint8_t index,uint8_t pinmode);
void IIC_Init(void);
void IIC_Start(void);
void IIC_Stop(void);
void IIC_Ack(uint8_t ack_mode);
uint8_t IIC_Wait_Ack(void);
uint8_t IIC_Write_Byte(uint8_t value);
uint8_t IIC_Read_Byte(void);
void IIC_Delay(uint32_t dly_time );
void IIC_Stable(uint32_t dly_time);
void AUTH_RESET_PIN_Init(void);
uint8_t mop_Api_iic_dev_status(uint8_t opmode);
uint8_t mop_Api_iic_write_data(uint8_t reg,uint8_t *orig,uint8_t len);
uint8_t mop_Api_iic_read_data(uint8_t reg,uint8_t *buf,uint8_t len);
void AUTH_CHIP_Rst(void);

//uint32_t mop_Api_iic_write_data(uint8_t reg,uint8_t *orig,uint8_t len);
//uint32_t mop_Api_iic_read_data(uint8_t reg,uint8_t *buf,uint8_t len);
#endif
